﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace SharpWeb
{
    /// <summary>
    /// option标签
    /// </summary>
    public class OptionComponent : TagComponent
    {
        protected override string TagName
        {
            get { return "option"; }
        }

        private string _Text;
        /// <summary>
        /// 选项显示的文本
        /// </summary>
        public string Text
        {
            get { return _Text; }
            set { _Text = value; }
        }

        /// <summary>
        /// 获取或设置option的value属性
        /// </summary>
        public string Value
        {
            get { return this.Attributes["value"]; }
            set { this.Attributes["value"] = value; }
        }

        protected override void OnRenderContent(StringBuilder sb, ComponentContext context)
        {
            base.OnRenderContent(sb, context);
            sb.Append(this.Text);
        }

    }

    public class OptionTagCollection:KeyedCollection<string,OptionComponent>
    {
        public void Add(string text, string value)
        {
            this.Add(new OptionComponent() { Text=text,Value=value});
        }

        protected override string GetKeyForItem(OptionComponent item)
        {
            return item.ComponentName;
        }
    }
}
